package com.sfx.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sfx.admin.common.convention.result.Result;
import com.sfx.admin.common.convention.result.Results;
import com.sfx.admin.remote.ShortLinkActualRemoteService;
import com.sfx.admin.remote.dto.req.ShortLinkCreateReqDO;
import com.sfx.admin.remote.dto.req.ShortLinkPageReqDTO;
import com.sfx.admin.remote.dto.req.ShortLinkUpdateReqDTO;
import com.sfx.admin.remote.dto.resp.ShortLinkCreateRespDTO;
import com.sfx.admin.remote.dto.resp.ShortLinkGroupCountRespDTO;
import com.sfx.admin.remote.dto.resp.ShortLinkPageRespDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
public class ShortLinkController {

    private final ShortLinkActualRemoteService shortLinkActualRemoteService;


    @PostMapping("/api/short-link/admin/v1/create")
    public Result<ShortLinkCreateRespDTO> createShortLink(@RequestBody ShortLinkCreateReqDO shortLinkCreateReqDO) {
        return shortLinkActualRemoteService.createShortLink(shortLinkCreateReqDO);
    }

    @GetMapping("/api/short-link/admin/v1/page")
    public Result<Page<ShortLinkPageRespDTO>> shortLinkPage(ShortLinkPageReqDTO shortLinkPageReqDTO) {
        return shortLinkActualRemoteService.shortLinkPage(shortLinkPageReqDTO.getGid(),shortLinkPageReqDTO.getOrderTag(),
                shortLinkPageReqDTO.getCurrent(),shortLinkPageReqDTO.getSize());
    }

    @GetMapping("/api/short-link/admin/v1/count")
    public Result<List<ShortLinkGroupCountRespDTO>> getGroupShortLinkCount(@RequestBody List<String> requestParam) {
        return shortLinkActualRemoteService.getGroupShortLinkCount(requestParam);
    }


    @PostMapping("/api/short-link/admin/v1/update")
    public Result<Void> updateShortLink(@RequestBody ShortLinkUpdateReqDTO requestParam) {
        shortLinkActualRemoteService.updateShortLink(requestParam);
        return Results.success();
    }
}